package org.bot.plugin.web.event;

import org.bot.api.event.DataStorage;
import org.bot.api.event.EventName;
import org.bot.api.util.StringUtil;
import org.bot.api.event.Events;
import org.bot.api.flow.FlowNode;
import org.bot.plugin.web.util.SelectorType;
import org.bot.plugin.web.util.WebApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 沧月
 * @create 0012 2023/9/12 17:05
 * @description <点击事件>
 * <p>
 * config   {"cmd":"org.bot.plugin.web.event.WebClick","arg":"/html/body/div/div/div[2]/form/button","selectorType":"xpath"}
 */

@Component
@EventName("单击")
public class WebClick implements Events {

    @Autowired
    WebApi webApi;


    @Override
    public Object exec(FlowNode note, DataStorage data) {
        String param;
        if (StringUtil.isNotNull(note.getDataIndex())) {
            param = data.get(note.getDataIndex()).toString();
        } else {
            param = note.getArg();
        }
        return webApi.click(webApi.getWebDriver(note), SelectorType.getType(note.getSelectorType()), param);
    }
}
